﻿using System;
using System.Linq;
using System.Collections.Generic; 
using System.Data;
using Matrix.Common.Utility;
using Matrix.MaKaYunShang.Model;
using Matrix.MaKaYunShang.DAL;
using Matrix.MaKaYunShang.Model.Dto;

namespace Matrix.MaKaYunShang.BLL
{
	public partial class IndustryBLL : BaseBLL<IndustryBLL>
	{
		#region 默认方法
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Industry model)
		{
			return IndustryDAL.Instance.Add(model);		
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Industry model)
		{
			return IndustryDAL.Instance.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{			
			return IndustryDAL.Instance.Delete(Id);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return IndustryDAL.Instance.DeleteList(Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Industry GetModel(int Id)
		{
			var ds = IndustryDAL.Instance.GetModel(Id);
            return ds == null ? null : ServicesHelper.DataSetToIList<Industry>(ds).ToList()[0];
		}
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Industry> GetModelList(string strWhere = null)
		{
			var ds = IndustryDAL.Instance.GetList(strWhere);
			return ServicesHelper.DataSetToIList<Industry>(ds).ToList();
		}
		#endregion
		
		#region 扩展方法
        /// <summary>
        /// 获得分页数据列表
        /// </summary>
        public TableDataViewDto<ViewIndustryDto> GetPagingList(int draw, int pageIndex, int pageSize, string searchKeyWord, string colOrder)
        {
            try
            {
                var totalCount = 0;
                var list = IndustryDAL.Instance.GetPagingList(pageIndex, pageSize, searchKeyWord, colOrder, ref totalCount);
                list.ForEach(a =>
                {
                    a.Action =
                        "<a class='btn btn-warning' href='javascript:;' onclick=updateData(" + a.Id + ");>修改</a> " +
                        "<a class='btn btn-danger' href='javascript:;' onclick=deleteData(" + a.Id + ");>删除</a>";
                });
                var returnDataList = new TableDataViewDto<ViewIndustryDto>
                {
                    data = list,
                    draw = draw,
                    recordsFiltered = totalCount,
                    recordsTotal = totalCount
                };
                return returnDataList;
            }
            catch (Exception ex)
            {
                _fileLog.Error(" GetPagingList | Exception: " + ex);
                return null;
            }
        }

        /// <summary>
        /// 根据关键字获得数据列表
        /// </summary>
        /// <param name="keyWord">关键字</param>
        /// <param name="parentType">0查询所有行业  1查询一级行业  2查询细分行业</param>
        public List<Industry> GetListByKeyWord(string keyWord, int parentType)
        {
            var ds = IndustryDAL.Instance.GetListByKeyWord(keyWord, parentType);
            return ServicesHelper.DataSetToIList<Industry>(ds).ToList();
        }
		#endregion
	}
}